import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as Elicons from '@element-plus/icons-vue';
import router from './router'
import './style/index.less'
import 'amfe-flexible'
import { i18n } from '@/i18n/index'

// 在使用函数组件时，unplugin-vue-components 无法自动引入对应的样式，因此需要手动引入样式
import 'vant/es/toast/style';
import 'vant/es/dialog/style';
import 'vant/es/notify/style';
import 'vant/es/image-preview/style';

const url = new URL(window.location.href)
if(url.searchParams.get("lang") && url.searchParams.get("lang") === "zh") {
  // localStorage.setItem("lang", "zh")
  sessionStorage.setItem("lang", "zh")
  window.location.href = window.location.href.split("?")[0]
} else if(url.searchParams.get("lang") && url.searchParams.get("lang") === "en") {
  // localStorage.setItem("lang", "en")
  sessionStorage.setItem("lang", "en")
  window.location.href = window.location.href.split("?")[0]
} else if(url.searchParams.get("lang")) {
  window.location.href = window.location.href.split("?")[0]
} 

const app = createApp(App);

// 全局注册element-plus icon
Object.keys(Elicons).forEach((key) => {
  app.component(key, Elicons[key]);
});

app.use(router)
app.use(ElementPlus)
app.use(i18n)
app.mount('#app')
